package com.prik.command.commands;

import com.prik.command.Command;
import com.prik.command.products.ElectricFan;
import com.prik.command.products.Stereo;

/**
 * 电风扇 高风速 命令
 **/
public class ElectricFanSpeedHighCommand implements Command {

    ElectricFan fan;

    /**
     * 记录之前的风速
     */
    int prevSpeed;

    public ElectricFanSpeedHighCommand(ElectricFan fan) {
        this.fan = fan;
    }

    @Override
    public void execute() {
        // 记录风速
        prevSpeed = fan.getSpeed();
        fan.speedHigh();
    }

    /**
     * 撤销，恢复之前的风速
     */
    @Override
    public void undo() {
        if (prevSpeed == ElectricFan.HIGH) {
            fan.speedHigh();
        } else if (prevSpeed == ElectricFan.MEDIUM) {
            fan.speedMedium();
        } else if (prevSpeed == ElectricFan.LOW) {
            fan.speedLow();
        } else if (prevSpeed == ElectricFan.OFF) {
            fan.turnOff();
        }
    }
}